package com.bears.god.sup.servlet.toAction;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bears.god.sup.model.Income;
import com.bears.god.sup.service.ServiceDAOFactory;

@WebServlet("/Income")
public class toIncomeServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");

		String num = req.getParameter("id");
		if (num != null) {
			try {
				List<Income> incomelist = ServiceDAOFactory.getIncomeDAO().findByfiveId((new Integer(num) - 1) * 5, 5);
				req.getSession().setAttribute("incomelist", incomelist);
				req.getRequestDispatcher("WEB-INF/view/manager/indexM.jsp").forward(req, resp);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			try {
				List<Income> incomelist = ServiceDAOFactory.getIncomeDAO().findByfiveId(0, 5);
				req.getSession().setAttribute("incomelist", incomelist);
				req.getRequestDispatcher("WEB-INF/view/manager/indexM.jsp").forward(req, resp);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
}
